home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-9.10-netbook-remix-PL.iso / casper / filesystem.squashfs / usr / share / pyshared / deluge / log.py < prev    next >
Text File  |  2009-06-16  |  2KB  |  84 lines

  1. #
  2. # log.py
  3. #
  4. # Copyright (C) 2007 Andrew Resch <andrewresch@gmail.com>
  5. #
  6. # Deluge is free software.
  7. #
  8. # You may redistribute it and/or modify it under the terms of the
  9. # GNU General Public License, as published by the Free Software
  10. # Foundation; either version 3 of the License, or (at your option)
  11. # any later version.
  12. #
  13. # deluge is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16. # See the GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with deluge.    If not, write to:
  20. #     The Free Software Foundation, Inc.,
  21. #     51 Franklin Street, Fifth Floor
  22. #     Boston, MA  02110-1301, USA.
  23. #
  24. #    In addition, as a special exception, the copyright holders give
  25. #    permission to link the code of portions of this program with the OpenSSL
  26. #    library.
  27. #    You must obey the GNU General Public License in all respects for all of
  28. #    the code used other than OpenSSL. If you modify file(s) with this
  29. #    exception, you may extend this exception to your version of the file(s),
  30. #    but you are not obligated to do so. If you do not wish to do so, delete
  31. #    this exception statement from your version. If you delete this exception
  32. #    statement from all source files in the program, then also delete it here.
  33. #
  34.  
  35. #
  36.  
  37.  
  38. """Logging functions"""
  39.  
  40. import logging
  41.  
  42. levels = {
  43.     "info": logging.INFO,
  44.     "warning": logging.WARNING,
  45.     "error": logging.ERROR,
  46.     "none": logging.CRITICAL,
  47.     "debug": logging.DEBUG
  48. }
  49. def setupLogger(level="error", filename=None):
  50.     """
  51.     Sets up the basic logger and if `:param:filename` is set, then it will log
  52.     to that file instead of stdout.
  53.  
  54.     :param level: str, the level to log
  55.     :param filename: str, the file to log to
  56.     """
  57.  
  58.     if not level or level not in levels:
  59.         level = "error"
  60.  
  61.     logging.basicConfig(
  62.         level=levels[level],
  63.         format="[%(levelname)-8s] %(asctime)s %(module)s:%(lineno)d %(message)s",
  64.         datefmt="%H:%M:%S",
  65.         filename=filename,
  66.         filemode="w"
  67.     )
  68.  
  69. def setLoggerLevel(level):
  70.     """
  71.     Sets the logger level.
  72.  
  73.     :param level: str, a string representing the desired level
  74.  
  75.     """
  76.     if level not in levels:
  77.         return
  78.  
  79.     global LOG
  80.     LOG.setLevel(levels[level])
  81.  
  82. # Get the logger
  83. LOG = logging.getLogger("deluge")
  84.